package com.bosssoft.cloud.wechat.common.infra.handler;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.bosssoft.cloud.notify.sender.SenderManager;
import com.bosssoft.cloud.wechat.common.bean.email.SendEipsEmailDTO;
import com.bosssoft.cloud.wechat.common.bean.email.SendEipsEmailParam;
import com.bosssoft.cloud.wechat.common.infra.properties.EipsManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 邮箱handler
 *
 * @author wcy create on 2021/7/9 11:53 上午
 */
@Slf4j
@Component
public class EmailHandler {

    @Resource
    private SenderManager senderManager;
    @Resource
    private EipsManager eipsManager;

    @Async
    public void send(SendEipsEmailParam param) {
        SendEipsEmailDTO dto = BeanUtil.toBean(param, SendEipsEmailDTO.class);
        dto.setDownloadtype(eipsManager.getDownloadtype());
        String content = JSON.toJSONString(dto);
        log.info("发送邮箱（异步）...");
        log.info("email:{},content:{}", param.getEmail(), content);
        senderManager.send(param.getEmail(), content, SenderManager.MAIL);
        log.info("发送成功");
    }
}
